﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Gfw.Infrastructure.Account;
using Gfw.Infrastructure.ExceptionImpl;
using Gfw.Repositories.Account;
using Gfw.Repository;

namespace Gfw.Infrastructure.Facilities
{
    /// <summary>
    /// 用户向公司的纳税
    /// </summary>
    public class Tax : IFacility
    {
        /// <summary>
        /// 纳税比例
        /// </summary>
        private const decimal TaxRatio = 0.02M;

        private string userId;
        private decimal award;
        private string taxationSerialNo;
        private string awardSerialNo;
        private decimal count;

        /// <summary>
        /// 动态奖金税收
        /// </summary>
        /// <param name="userId">贡献用户id</param>
        /// <param name="award">得奖金额</param>
        /// <param name="awardSerialNo">动态奖金流水号</param>
        /// <param name="taxationSerialNo">综合税收编号</param>
        public Tax(string userId, decimal count, string awardSerialNo, string taxationSerialNo)
        {
            this.userId = userId;
            //this.award = award;
            this.taxationSerialNo = taxationSerialNo;
            this.awardSerialNo = awardSerialNo;
            this.count = count;
        }

        public void Execute(UnitOfWork unitOfWork = null)
        {
            if (unitOfWork == null)
                throw new GfwTransactionInvalidException(ConstMessage.TransactionInvalid);


            var companyBargainRepository = new ActCompanyBargainRepository();
            //添加公司
            companyBargainRepository.AddIncome(userId, (int)CompanyTradeTypeEnum.Sell_Stock, count, "", awardSerialNo,
                                               taxationSerialNo, unitOfWork);
        }
    }
}
